﻿@page "/"
@layout FrontLayout
@inject NavigationManager NavigationManager
@inject IMessageService MessageService

<PageTitle>爱看剧</PageTitle>

<div class="home" style="height: 100%;">
    <!-- 头部 -->
    <div class="head" style="display: flex; flex-direction: row; justify-content: space-between">
        <div style="padding: 2px 15px;text-align: center">
            <h1 style="margin: 20px 0; font-size: 38px; color: darkorange">
                爱看剧
            </h1>
            <div style="line-height: 10px; color: #0bbdd4;">
                <p class="">收录那些年陪伴我们成长的经典影视剧</p>
                <p class="">重温经典、重获喜悦与感动！</p>
            </div>
        </div>

        <div style="margin: auto 0;padding-right: 15px;">
            <AntDesign.Input TValue="string" @bind-Value="@_searchTxt">
                <AddOnBefore>
                    <SimpleSelect @bind-Value="@_searchType" Placeholder="选择分类" Style="width: unset;">
                        <SelectOptions>
                            <SimpleSelectOption Value="1" Label="电视剧"></SimpleSelectOption>
                            <SimpleSelectOption Value="2" Label="电影"></SimpleSelectOption>
                            <SimpleSelectOption Value="3" Label="动漫"></SimpleSelectOption>
                        </SelectOptions>
                    </SimpleSelect>
                </AddOnBefore>
                <AddOnAfter>
                    <Icon Type="search" OnClick="@DoSearch" Style="cursor: pointer;"></Icon>
                </AddOnAfter>
            </AntDesign.Input>
        </div>
    </div>

    <!-- 主内容 -->
    <div class="main" style="padding: 40px 5% 0 5%;">
        <Space Size=@(("50", "20")) Align="center" Wrap>
            <SpaceItem>
                <div class="link-card card-teleplay" @onclick="GoToTeleplay">
                    <span class="link-card-name">电视剧</span>
                </div>
            </SpaceItem>
            <SpaceItem>
                <div class="link-card card-movie" @onclick="GoToMovie">
                    <span class="link-card-name">电影</span>
                </div>
            </SpaceItem>
            <SpaceItem>
                <div class="link-card card-animation" @onclick="GoToAnimation">
                    <span class="link-card-name">动漫</span>
                </div>
            </SpaceItem>
        </Space>
    </div>
</div>


@code {
    private string _searchType = string.Empty;
    private string _searchTxt = string.Empty;

    private void DoSearch()
    {
        if (string.IsNullOrWhiteSpace(_searchType))
        {
            MessageService.Warning("请选择分类", 1.5);
            return;
        }
        if (string.IsNullOrWhiteSpace(_searchTxt))
        {
            MessageService.Warning("请输入搜索内容", 1.5);
            return;
        }
        NavigationManager.NavigateTo($"/search?type={_searchType}&keyword={_searchTxt}");
    }

    private void GoToTeleplay()
    {
        NavigationManager.NavigateTo("/teleplay", true);
    }

    private void GoToMovie()
    {
        NavigationManager.NavigateTo("/movie", true);
    }

    private void GoToAnimation()
    {
        NavigationManager.NavigateTo("/animation", true);
    }
}